export default class Dictionary {
    private _container: Object;
    public get container(): Object { return this._container; }


    public constructor() {
        this._container = new Object();
    }


    private _length: number = 0;
    public get length(): number { return this._length; }


    /**
     * 添加元素数据
     * @param key 
     * @param value 
     */
    public add(key: any, value: any): void {
        if (!this.containsKey(key)) {
            this._length++;
        }
        this._container[key] = value;
    }

    /**
     * 获取元素数据
     * @param key 
     */
    public get(key: any): any {
        return this._container[key];
    }

    /**
     * 重置元素数据
     * @param key 
     * @param value 
     */
    public reset(key: any, value: any): void {
        if (this.containsKey(key)) {
            this._container[key] = value;
        } else {
            console.warn('Dictionary: warning you reset a not exist key(' + key + ')');
        }
    }

    /**
     * 是否包含元素
     * @param key 
     */
    public containsKey(key: any): boolean {
        return this._container.hasOwnProperty(key);
    }

    /**
     * 移除元素数据
     * @param key 
     */
    public remove(key: any): void {
        if (this.containsKey(key)) {
            this._container[key] = null;
            delete this._container[key];
            this._length--;
        }
    }

    /**
     * 清除
     */
    public clear(): void {
        this._length = 0;
        this._container = null;
        this._container = new Object();
    }
}
